//
//  VCLogin.m
//  Astro
//
//  Created by Trinh Huy Cuong on 11/28/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "VCLogin.h"
#import "VCSignUp.h"
#import "VCAccount.h"

@implementation VCLogin

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization.
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Đăng nhập";
	
	AstroAppDelegate *appDelegate = APP_DELEGATE;
	self.navigationItem.rightBarButtonItem = appDelegate.mainButtonItem;
}

- (void) viewWillAppear:(BOOL)animated{
	[self.navigationController setNavigationBarHidden:NO animated:YES];
	AstroAppDelegate *appDelegate = APP_DELEGATE;
	[appDelegate bottomButtonControlWithState:BBStateHide andType:BBTypeEast];
	appDelegate = nil;
}

- (IBAction) btClick_loginAction{
	NSLog(@"abc");
	
	if ([CTServer requestURLSignInWithUserName:tf_userName.text andPassword:tf_password.text]) {
		[(AstroAppDelegate*)[[UIApplication sharedApplication] delegate] setUserInfo:[CTServer requestURLGetUserWithUserName:tf_userName.text]];

		VCAccount *account = [[VCAccount alloc] initWithNibName:@"VCAccount" bundle:nil];
		account.login = self;
		[self.navigationController pushViewController:account animated:YES];	
		[account release];		
	}
	else {
		[Lib showAlert:@"Dang nhap loi" withMessage:nil];
	}
}

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	[tf_password resignFirstResponder];
	[tf_userName resignFirstResponder];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations.
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (IBAction) showVCSignUp{
	VCSignUp *signup = [[VCSignUp alloc] initWithNibName:@"VCSignUp" bundle:nil];
	signup.login = self;
	[self.navigationController pushViewController:signup animated:YES];
	[signup release];
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
